# simplecov must be loaded FIRST. Only the files required after it gets loaded
# will be profiled !!!
if ENV['TEST_ENABLE_COVERAGE'] == '1'
    begin
        require 'simplecov'
        SimpleCov.start
    rescue LoadError
        require 'typelib'
        Typelib.warn "coverage is disabled because the 'simplecov' gem cannot be loaded"
    rescue Exception => e
        require 'typelib'
        Typelib.warn "coverage is disabled: #{e.message}"
    end
end

if ENV['TEST_DEBUG'] == '1'
    if RUBY_VERSION >= "2.0"
        require 'minitest/byebug'
    else
        require 'minitest/debugger'
    end
end

require 'typelib'
Typelib.load_type_plugins = false
# This file is generated by CMake. The test must be run with the right -I option
# so that we can require it 'as-is'
require 'test_config'
require 'minitest/autorun'
require 'minitest/spec'
require 'flexmock/minitest'

if ENV['TEST_ENABLE_PRY'] != '0'
    begin
        require 'pry'
    rescue Exception
        Typelib.warn "debugging is disabled because the 'pry' gem cannot be loaded"
    end
end

module Typelib
    module SelfTest
        def setup
            @__warn_about_helper_method_clashes = Typelib.warn_about_helper_method_clashes?
            Typelib.warn_about_helper_method_clashes = false
            super
        end

        def teardown
            super
            Typelib.warn_about_helper_method_clashes = @__warn_about_helper_method_clashes
        end
    end
end

module Minitest
    class Test
        include Typelib::SelfTest
    end
end

